package com.ruoyi.web.controller.system;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SysAppUser;
import com.ruoyi.system.service.ISysAppUserService;

/**
 * 手机用户信息明细Controller
 * 
 * @author ruoyi
 * @date 2020-10-18
 */
@Controller
@RequestMapping("/system/appuser")
public class SysAppUserController extends BaseController {
	private String prefix = "system/appuser";

	@Autowired
	private ISysAppUserService sysAppUserService;

	@RequiresPermissions("system:user:view")
	@GetMapping()
	public String user() {
		return prefix + "/user";
	}

	/**
	 * 查询手机用户信息明细列表
	 */
	@RequiresPermissions("system:user:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(SysAppUser sysAppUser) {
		startPage();
		List<SysAppUser> list = sysAppUserService.selectSysAppUserList(sysAppUser);
		return getDataTable(list);
	}

	/**
	 * 导出手机用户信息明细列表
	 */
	@RequiresPermissions("system:user:export")
	@Log(title = "手机用户信息明细", businessType = BusinessType.EXPORT)
	@PostMapping("/export")
	@ResponseBody
	public AjaxResult export(SysAppUser sysAppUser) {
		List<SysAppUser> list = sysAppUserService.selectSysAppUserList(sysAppUser);
		ExcelUtil<SysAppUser> util = new ExcelUtil<SysAppUser>(SysAppUser.class);
		return util.exportExcel(list, "user");
	}

	/**
	 * 新增手机用户信息明细
	 */
	@GetMapping("/add")
	public String add() {
		return prefix + "/add";
	}

	/**
	 * 新增保存手机用户信息明细
	 */
	@RequiresPermissions("system:user:add")
	@Log(title = "手机用户信息明细", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(SysAppUser sysAppUser) {
		return toAjax(sysAppUserService.insertSysAppUser(sysAppUser));
	}

	/**
	 * 修改手机用户信息明细
	 */
	@GetMapping("/edit/{id}")
	public String edit(@PathVariable("id") Long id, ModelMap mmap) {
		SysAppUser sysAppUser = sysAppUserService.selectSysAppUserById(id);
		mmap.put("sysAppUser", sysAppUser);
		return prefix + "/edit";
	}

	/**
	 * 修改保存手机用户信息明细
	 */
	@RequiresPermissions("system:user:edit")
	@Log(title = "手机用户信息明细", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(SysAppUser sysAppUser) {
		return toAjax(sysAppUserService.updateSysAppUser(sysAppUser));
	}

	/**
	 * 删除手机用户信息明细
	 */
	@RequiresPermissions("system:user:remove")
	@Log(title = "手机用户信息明细", businessType = BusinessType.DELETE)
	@PostMapping("/remove")
	@ResponseBody
	public AjaxResult remove(String ids) {
		return toAjax(sysAppUserService.deleteSysAppUserByIds(ids));
	}
}
